// Protocol3 商户渠道配置协议数据 - 直连商户模式
// 从 protocols-merchant-direct.ts 迁移而来，转换为 Protocol3 格式

import { type MerchantChannelConfig3, ProtocolType3, FieldType } from '../types/protocol3-types'

// 微信支付直连商户配置
const wechatDirectMerchantConfig: MerchantChannelConfig3 = {
  protocolId: 'PROTOCOL3_WXPAY_DIRECT_MERCHANT',
  protocolType: ProtocolType3.MERCHANT_CHANNEL_CONFIG_V3,
  channelCode: 'CHANNEL_IF_WXPAY',
  channelName: '微信支付',
  name: '微信支付直连商户渠道配置',
  version: '3.0.0',
  description: '商户直连微信支付的配置参数',
  configType: 'DIRECT_MERCHANT',
  configSections: [
    {
      sectionKey: 'basic',
      sectionName: '基础配置',
      description: '微信支付商户直连基础配置',
      icon: 'SettingOutlined',
      order: 1,
      collapsed: false,
      fields: [
        {
          fieldKey: 'appId',
          fieldName: '应用ID',
          fieldType: FieldType.INPUT,
          required: true,
          defaultValue: '',
          placeholder: '请输入微信应用ID',
          description: '微信公众平台或开放平台分配的应用ID',
          helpText: 'wx开头的18位字符',
          validation: {
            pattern: '^wx[a-zA-Z0-9]{16}$',
            message: '应用ID格式不正确，应为wx开头的18位字符'
          }
        },
        {
          fieldKey: 'mchId',
          fieldName: '商户号',
          fieldType: FieldType.INPUT,
          required: true,
          defaultValue: '',
          placeholder: '请输入微信支付商户号',
          description: '微信支付分配的商户号',
          helpText: '10位数字的商户号',
          validation: {
            pattern: '^[0-9]{10}$',
            message: '商户号应为10位数字'
          }
        },
        {
          fieldKey: 'apiKey',
          fieldName: 'API密钥',
          fieldType: FieldType.PASSWORD,
          required: true,
          defaultValue: '',
          placeholder: '请输入API密钥',
          description: '商户平台设置的API密钥，用于签名验证',
          helpText: '32位字符的API密钥',
          validation: {
            minLength: 32,
            maxLength: 32,
            message: 'API密钥长度必须为32位'
          }
        },
        {
          fieldKey: 'apiVersion',
          fieldName: 'API版本',
          fieldType: FieldType.SELECT,
          required: true,
          defaultValue: 'v3',
          options: [
            { label: 'API v2', value: 'v2' },
            { label: 'API v3', value: 'v3' }
          ],
          description: '选择使用的微信支付API版本'
        },
        {
          fieldKey: 'notifyUrl',
          fieldName: '回调地址',
          fieldType: FieldType.INPUT,
          required: true,
          defaultValue: '',
          placeholder: '请输入支付回调地址',
          description: '支付结果通知回调地址',
          helpText: '有效的HTTP(S)地址',
          validation: {
            pattern: '^https?://[^\\s]+$',
            message: '请输入有效的HTTP(S)地址'
          }
        },
        {
          fieldKey: 'sandboxMode',
          fieldName: '沙盒模式',
          fieldType: FieldType.SWITCH,
          required: false,
          defaultValue: false,
          description: '是否启用沙盒测试环境'
        }
      ],
      defaultValues: {
        appId: '',
        mchId: '',
        apiKey: '',
        apiVersion: 'v3',
        notifyUrl: '',
        sandboxMode: false
      }
    }
  ],
  uiConfig: {
    layout: 'vertical',
    labelWidth: 120
  },
  metadata: {
    author: 'AnyPay Team',
    createTime: '2024-01-01',
    updateTime: '2024-01-15',
    tags: ['微信支付', '直连商户'],
    category: '直连商户配置',
    documentation: '微信支付直连商户配置协议'
  },
  enabled: true
}

// 支付宝直连商户配置
const alipayDirectMerchantConfig: MerchantChannelConfig3 = {
  protocolId: 'PROTOCOL3_ALIPAY_DIRECT_MERCHANT',
  protocolType: ProtocolType3.MERCHANT_CHANNEL_CONFIG_V3,
  channelCode: 'CHANNEL_IF_ALIPAY',
  channelName: '支付宝',
  name: '支付宝直连商户渠道配置',
  version: '3.0.0',
  description: '商户直连支付宝的配置参数',
  configType: 'DIRECT_MERCHANT',
  configSections: [
    {
      sectionKey: 'basic',
      sectionName: '基础配置',
      description: '支付宝商户直连基础配置',
      icon: 'SettingOutlined',
      order: 1,
      collapsed: false,
      fields: [
        {
          fieldKey: 'appId',
          fieldName: '应用ID',
          fieldType: FieldType.INPUT,
          required: true,
          defaultValue: '',
          placeholder: '请输入支付宝应用ID',
          description: '支付宝开放平台创建应用后生成的应用ID',
          helpText: '16位数字',
          validation: {
            pattern: '^[0-9]{16}$',
            message: '应用ID应为16位数字'
          }
        },
        {
          fieldKey: 'pid',
          fieldName: '合作伙伴ID',
          fieldType: FieldType.INPUT,
          required: true,
          defaultValue: '',
          placeholder: '请输入合作伙伴ID',
          description: '支付宝分配的合作伙伴ID',
          helpText: '16位数字',
          validation: {
            pattern: '^[0-9]{16}$',
            message: '合作伙伴ID应为16位数字'
          }
        },
        {
          fieldKey: 'privateKey',
          fieldName: '应用私钥',
          fieldType: FieldType.TEXTAREA,
          required: true,
          defaultValue: '',
          placeholder: '请输入应用私钥',
          description: '应用私钥，用于签名',
          uiProps: { rows: 6 },
          validation: {
            pattern: '^-----BEGIN (RSA )?PRIVATE KEY-----[\\s\\S]*-----END (RSA )?PRIVATE KEY-----$',
            message: '请输入有效的RSA私钥格式'
          }
        },
        {
          fieldKey: 'publicKey',
          fieldName: '支付宝公钥',
          fieldType: FieldType.TEXTAREA,
          required: true,
          defaultValue: '',
          placeholder: '请输入支付宝公钥',
          description: '支付宝公钥，用于验签',
          uiProps: { rows: 4 },
          validation: {
            pattern: '^-----BEGIN PUBLIC KEY-----[\\s\\S]*-----END PUBLIC KEY-----$',
            message: '请输入有效的公钥格式'
          }
        },
        {
          fieldKey: 'signType',
          fieldName: '签名算法',
          fieldType: FieldType.SELECT,
          required: true,
          defaultValue: 'RSA2',
          options: [
            { label: 'RSA', value: 'RSA' },
            { label: 'RSA2', value: 'RSA2' }
          ],
          description: '选择签名算法类型'
        },
        {
          fieldKey: 'notifyUrl',
          fieldName: '异步通知地址',
          fieldType: FieldType.INPUT,
          required: true,
          defaultValue: '',
          placeholder: '请输入异步通知地址',
          description: '支付结果异步通知地址',
          helpText: '有效的HTTP(S)地址',
          validation: {
            pattern: '^https?://[^\\s]+$',
            message: '请输入有效的HTTP(S)地址'
          }
        }
      ],
      defaultValues: {
        appId: '',
        pid: '',
        privateKey: '',
        publicKey: '',
        signType: 'RSA2',
        notifyUrl: ''
      }
    }
  ],
  uiConfig: {
    layout: 'vertical',
    labelWidth: 120
  },
  metadata: {
    author: 'AnyPay Team',
    createTime: '2024-01-01',
    updateTime: '2024-01-15',
    tags: ['支付宝', '直连商户'],
    category: '直连商户配置',
    documentation: '支付宝直连商户配置协议'
  },
  enabled: true
}

// 汇付天下直连商户配置
const huifuDirectMerchantConfig: MerchantChannelConfig3 = {
  protocolId: 'PROTOCOL3_HUIFU_DIRECT_MERCHANT',
  protocolType: ProtocolType3.MERCHANT_CHANNEL_CONFIG_V3,
  channelCode: 'CHANNEL_IF_HUIFU',
  channelName: '汇付天下',
  name: '汇付天下直连商户渠道配置',
  version: '3.0.0',
  description: '商户直连汇付天下的配置参数',
  configType: 'DIRECT_MERCHANT',
  configSections: [
    {
      sectionKey: 'basic',
      sectionName: '基础配置',
      description: '汇付天下商户直连基础配置',
      icon: 'SettingOutlined',
      order: 1,
      collapsed: false,
      fields: [
        {
          fieldKey: 'merchantId',
          fieldName: '商户编号',
          fieldType: FieldType.INPUT,
          required: true,
          defaultValue: '',
          placeholder: '请输入商户编号',
          description: '汇付天下分配的商户编号',
          helpText: 'HF开头的编号',
          validation: {
            pattern: '^HF[0-9A-Z]{8,16}$',
            message: '商户编号格式不正确'
          }
        },
        {
          fieldKey: 'apiKey',
          fieldName: 'API密钥',
          fieldType: FieldType.PASSWORD,
          required: true,
          defaultValue: '',
          placeholder: '请输入API密钥',
          description: '汇付天下分配的API密钥',
          helpText: '不少于32位',
          validation: {
            minLength: 32,
            message: 'API密钥长度不能少于32位'
          }
        },
        {
          fieldKey: 'notifyUrl',
          fieldName: '通知地址',
          fieldType: FieldType.INPUT,
          required: true,
          defaultValue: '',
          placeholder: '请输入通知地址',
          description: '支付结果通知地址',
          helpText: '有效的HTTP(S)地址',
          validation: {
            pattern: '^https?://[^\\s]+$',
            message: '请输入有效的HTTP(S)地址'
          }
        }
      ],
      defaultValues: {
        merchantId: '',
        apiKey: '',
        notifyUrl: ''
      }
    }
  ],
  uiConfig: {
    layout: 'vertical',
    labelWidth: 120
  },
  metadata: {
    author: 'AnyPay Team',
    createTime: '2024-01-01',
    updateTime: '2024-01-15',
    tags: ['汇付天下', '直连商户'],
    category: '直连商户配置',
    documentation: '汇付天下直连商户配置协议'
  },
  enabled: true
}

// 斗拱支付直连商户配置
const dougongDirectMerchantConfig: MerchantChannelConfig3 = {
  protocolId: 'PROTOCOL3_DOUGONG_DIRECT_MERCHANT',
  protocolType: ProtocolType3.MERCHANT_CHANNEL_CONFIG_V3,
  channelCode: 'CHANNEL_IF_DOUGONG',
  channelName: '斗拱支付',
  name: '斗拱支付直连商户渠道配置',
  version: '3.0.0',
  description: '商户直连斗拱支付的配置参数',
  configType: 'DIRECT_MERCHANT',
  configSections: [
    {
      sectionKey: 'basic',
      sectionName: '基础配置',
      description: '斗拱支付商户直连基础配置',
      icon: 'SettingOutlined',
      order: 1,
      collapsed: false,
      fields: [
        {
          fieldKey: 'merchantId',
          fieldName: '商户号',
          fieldType: FieldType.INPUT,
          required: true,
          defaultValue: '',
          placeholder: '请输入商户号',
          description: '斗拱支付分配的商户号',
          helpText: '格式：DG开头后跟8-12位数字',
          validation: {
            pattern: '^DG[0-9]{8,12}$',
            message: '商户号格式不正确，应为DG开头'
          }
        },
        {
          fieldKey: 'apiKey',
          fieldName: 'API密钥',
          fieldType: FieldType.PASSWORD,
          required: true,
          defaultValue: '',
          placeholder: '请输入API密钥',
          description: '斗拱支付分配的API密钥',
          helpText: '长度应在32-64位之间',
          validation: {
            minLength: 32,
            maxLength: 64,
            message: 'API密钥长度应在32-64位之间'
          }
        },
        {
          fieldKey: 'notifyUrl',
          fieldName: '回调地址',
          fieldType: FieldType.INPUT,
          required: true,
          defaultValue: '',
          placeholder: '请输入回调地址',
          description: '支付结果回调通知地址',
          helpText: '有效的HTTP(S)地址',
          validation: {
            pattern: '^https?://[^\\s]+$',
            message: '请输入有效的HTTP(S)地址'
          }
        }
      ],
      defaultValues: {
        merchantId: '',
        apiKey: '',
        notifyUrl: ''
      }
    }
  ],
  uiConfig: {
    layout: 'vertical',
    labelWidth: 120
  },
  metadata: {
    author: 'AnyPay Team',
    createTime: '2024-01-01',
    updateTime: '2024-01-15',
    tags: ['斗拱支付', '直连商户'],
    category: '直连商户配置',
    documentation: '斗拱支付直连商户配置协议'
  },
  enabled: true
}

// 乐刷支付直连商户配置
const leshuaDirectMerchantConfig: MerchantChannelConfig3 = {
  protocolId: 'PROTOCOL3_LESHUA_DIRECT_MERCHANT',
  protocolType: ProtocolType3.MERCHANT_CHANNEL_CONFIG_V3,
  channelCode: 'CHANNEL_IF_LESHUA',
  channelName: '乐刷支付',
  name: '乐刷支付直连商户渠道配置',
  version: '3.0.0',
  description: '商户直连乐刷支付的配置参数',
  configType: 'DIRECT_MERCHANT',
  configSections: [
    {
      sectionKey: 'basic',
      sectionName: '基础配置',
      description: '乐刷支付商户直连基础配置',
      icon: 'SettingOutlined',
      order: 1,
      collapsed: false,
      fields: [
        {
          fieldKey: 'merchantId',
          fieldName: '商户号',
          fieldType: FieldType.INPUT,
          required: true,
          defaultValue: '',
          placeholder: '请输入乐刷支付商户号',
          description: '乐刷支付分配的商户号',
          helpText: '格式：10-15位数字',
          validation: {
            pattern: '^[0-9]{10,15}$',
            message: '商户号应为10-15位数字'
          }
        },
        {
          fieldKey: 'terminalId',
          fieldName: '终端号',
          fieldType: FieldType.INPUT,
          required: true,
          defaultValue: '',
          placeholder: '请输入终端号',
          description: '乐刷支付分配的终端号',
          helpText: '格式：8-12位数字',
          validation: {
            pattern: '^[0-9]{8,12}$',
            message: '终端号应为8-12位数字'
          }
        },
        {
          fieldKey: 'signKey',
          fieldName: '签名密钥',
          fieldType: FieldType.PASSWORD,
          required: true,
          defaultValue: '',
          placeholder: '请输入签名密钥',
          description: '用于API请求签名的密钥',
          helpText: '长度应在16-64个字符之间',
          validation: {
            minLength: 16,
            maxLength: 64,
            message: '签名密钥长度应在16-64个字符之间'
          }
        },
        {
          fieldKey: 'notifyUrl',
          fieldName: '异步通知地址',
          fieldType: FieldType.INPUT,
          required: true,
          defaultValue: '',
          placeholder: 'https://your-domain.com/notify/leshua',
          description: '接收支付结果异步通知的地址',
          helpText: '有效的HTTP(S)地址',
          validation: {
            pattern: '^https?://.*',
            message: '异步通知地址必须是有效的HTTP/HTTPS URL'
          }
        }
      ],
      defaultValues: {
        merchantId: '',
        terminalId: '',
        signKey: '',
        notifyUrl: ''
      }
    }
  ],
  uiConfig: {
    layout: 'vertical',
    labelWidth: 120
  },
  metadata: {
    author: 'AnyPay Team',
    createTime: '2024-01-15',
    updateTime: '2024-01-15',
    tags: ['乐刷支付', '直连商户'],
    category: '直连商户配置',
    documentation: '乐刷支付直连商户配置协议'
  },
  enabled: true
}

// 导出直连商户配置协议数据数组
export const protocol3DirectMerchantConfigs: MerchantChannelConfig3[] = [
  wechatDirectMerchantConfig,
  alipayDirectMerchantConfig,
  huifuDirectMerchantConfig,
  dougongDirectMerchantConfig,
  leshuaDirectMerchantConfig
]
